package com.inossem.warehousestorage_inossem.activity.out_storage;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStoragePickingOverviewBean;
import com.inossem.warehousestorage_inossem.dialog.DialogUtils;
import com.inossem.warehousestorage_inossem.utils.ActivityUtils;
import com.inossem.warehousestorage_inossem.utils.OutStorageUtils;
import com.zhy.android.percent.support.PercentRelativeLayout;

public class OutStoragePickingConfirmActivity extends BaseActivity {

    private TextView title, confirm, department, applicant, createTime, totalLine, submitLine;

    private PercentRelativeLayout submitOverviewLayout;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        setContentView(R.layout.activity_out_storage_picking_confirm);
        initView(OutStoragePickingConfirmActivity.this);
    }

    @Override
    protected void onResumeImpl() {
        initData(OutStoragePickingConfirmActivity.this);
    }

    private void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        confirm = (TextView) activity.findViewById(R.id.confirm);
        department = (TextView) activity.findViewById(R.id.department);
        applicant = (TextView) activity.findViewById(R.id.applicant);
        createTime = (TextView) activity.findViewById(R.id.createTime);
        totalLine = (TextView) activity.findViewById(R.id.totalLine);
        submitLine = (TextView) activity.findViewById(R.id.submitLine);
        submitOverviewLayout = (PercentRelativeLayout) activity.findViewById(R.id.submitOverviewLayout);
    }

    private void initData(Activity activity) {
        confirm.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                confirm(activity);
            }
        });
        ActivityUtils.initBackAndFunction(activity, R.string.activity_receive_add_receiver_title_short, new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                finish();
            }
        });

        getData(activity);
    }

    private void confirm(Context context) {
//        OutStoragePickingConfirmRequestBean params = OutStorageUtils.getOutStoragePickingConfirmRequestBean(context);
//        OutStoragePickingConfirmRequest.request(context, params, new GsonBeanListener<OutStorageConfirmBean>() {
//            @Override
//            public void onSuccess(OutStorageConfirmBean bean) {
//                SPUtils.removePickingOutStorageInformation(context);
//                if (!TextUtils.isEmpty(bean.getHead().getMsg())) {
//                    Utils.middleToast(context, bean.getHead().getMsg());
//                }
//                Intent intent = new Intent(context, OutStorageResultActivity.class);
//                startActivity(intent);
//            }
//
//            @Override
//            public void onFailing(OutStorageConfirmBean bean) {
//                if (!TextUtils.isEmpty(bean.getBody())) {
//                    OutStorageUtils.updatePickingOutStorageNumber(context, bean.getBody());
//                }
//            }
//        });
    }

    private void getData(Context context) {
        OutStoragePickingOverviewBean.BodyBean data = OutStorageUtils.getOutStoragePickingOverviewBean(context).getBody();
        department.setText(data.getApply_depart_name());
        applicant.setText(data.getApply_user_name());
        createTime.setText(data.getApply_time());
        title.setText(data.getRefer_receipt_code());
        totalLine.setText(data.getItem_list().size() + "");
        submitLine.setText(OutStorageUtils.getPickingOutStorageNumber(context) + "");
        submitOverviewLayout.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                DialogUtils.getOverviewDialog(context, OutStorageUtils.getOverViewBeanWithPickingOutStorageList(data.getItem_list())).show();
            }
        });
    }

}
